# @time     :2022/1/19
# @Author   :Simple
# @FileName :handle_yaml
import os

import yaml

from config import BASE_CAPS_DIR
from util.logger import log as logger


def read_yaml(file):
    """
    read yaml file
    """
    if not os.path.exists(file):
        logger.error("file not exists")
        raise FileNotFoundError
    with open(file, 'r', encoding="utf-8") as f:
        return yaml.safe_load(f)


def write_yaml(content, file):
    if not os.path.exists(file):
        logger.error("file not exists")
        raise FileNotFoundError
    with open(file, 'w', encoding='utf-8') as f:
        yaml.safe_dump(content, f)


def get_base_caps():
    """
    get capabilities
    """
    base_caps = read_yaml(BASE_CAPS_DIR)
    return base_caps


# if __name__ == '__main__':
#     content = get_base_caps()
#     import config
#     file = os.path.join(config.BASE_DIR, "data/pt.yaml")
#     write_yaml(content, file)

